package name.huzhenbo.java.algorithm.talent;

import java.util.Random;

/**
 * Effective Java, Item 40
 *
 * Prefer two-element enum types to boolean parameters
 */
public enum Person {
    GOOD_PERSON(Type.GOOD), BAD_PERSON(Type.BAD);

    private Type type;

    private Person(Type type) {
        this.type = type;
    }

    public boolean isGood() {
        return Type.GOOD.equals(type);
    }

    /**
     * Good person only tell truth, but bad person is not sure.
     *
     * @param another
     * @return
     */
    public boolean tell(Person another) {
        if (isGood()) {
            return another.isGood();
        } else {
            return new Random().nextBoolean();
        }
    }

    private static enum Type{
        GOOD, BAD
    }
}
